<template>
  <div>
    <Header />
    <nuxt class="body" />
    <Footer />
  </div>
</template>
<script>
import Header from "@/components/header.vue";
import Footer from "@/components/footer.vue";
export default {
  components: {
    Header,
    Footer
  },
  created() {
     this.$axios.get("/api2/statstic/addcount?type=visit")
  },
  mounted() {
    //刷新会调用到
    window.addEventListener("beforeunload", e => this.beforeunloadFn());
    //关闭标签页时会调用到
    window.addEventListener("unload", e => this.unloadFn());
   
  },
  destroyed() {
    //刷新会调用到
    window.addEventListener("beforeunload", e => this.beforeunloadFn());
    //关闭标签页时会调用到
    window.addEventListener("unload", e => this.unloadFn());
  },
  data() {
    return {
      _beforeUnload_time: 0,
      _gap_time: 0
    };
  },
  methods: {
    beforeunloadFn() {
      this._beforeUnload_time = new Date().getTime();
    },
    unloadFn() {
      this._gap_time = new Date().getTime() - this._beforeUnload_time;
        // this.$axios.get("/api2/statstic/addcount?type=visit").then(res=>{
        //   })
      if (this._gap_time <= 5) {
          this.$store.commit("user/clearUserInfo");
        //关闭时，清空session
      }
    }
  }
};
</script>

<style scoped>
.body {
  background: #ffffff;
}
/* *{
  margin: 0;
  padding: 0;
}
ul,li,ol{
  list-style: none;
}
a{
  color: #333;
  text-decoration: none;
}
em,i{
  font-style: normal ;
} */
</style>
